package fun.taostool.common;

import fun.taostool.common.constant.RespCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @description: 响应异常
 * @author: Chensn
 * @time: 2024/10/31
 */

@Data
@EqualsAndHashCode(callSuper = false)
public class ResponseException extends RuntimeException {

    private static final long serialVersionUID = 1L;
    private String code;

    private RespCodeEnum respCodeEnum;

    private ResponseData responseData;

    /**
     * 无参构造方法
     */
    public ResponseException() {
        super();
    }

    /**
     * 无参构造方法
     */
   /* public ResponseException(String code,String message) {
        super(message);
        this.code = code;
    }*/

    /**
     * 有参构造方法
     *
     * @param message
     */
    public ResponseException(String message) {
        super(message);
        this.code = "300";
    }

    public ResponseException(ResponseData responseData) {
        this.responseData = responseData;
    }

    /**
     * 有参构造方法
     *
     * @param respCodeEnum
     */
    public ResponseException(RespCodeEnum respCodeEnum) {
        super(respCodeEnum.getMsgDes());
        this.code = respCodeEnum.getMsgCode();
        this.respCodeEnum = respCodeEnum;
    }

    public RespCodeEnum getRespCodeEnum() {
        return respCodeEnum;
    }

    public static ResponseException of(String message, Object... args) {
        return new ResponseException(String.format(message.replaceAll("\\{\\}", "%s"), args));
    }
}
